//
//  IGTabbarController.swift
//  InternshipGo
//
//  Created by zhujinhui on 15/12/10.
//  Copyright © 2015年 kyson. All rights reserved.
//

import UIKit


class IGTabbarController: UITabBarController,UITabBarControllerDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let homeVC = HomeViewController.init(nibName : "HomeViewController", bundle: nil);
        let chatVC = ChatViewController.init(nibName : "ChatViewController", bundle: nil);
        let aboutVC = AboutViewController.init(nibName : "AboutViewController", bundle: nil);
        
        var imageTabHome = UIImage.init(named: "icon_home")
        imageTabHome = imageTabHome?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

        var imageMake = UIImage.init(named: "icon_make")
        imageMake = imageMake?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        var imageMine = UIImage.init(named: "icon_about")
        imageMine = imageMine?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        let homeTabbarItem = UITabBarItem.init(title: "主页", image: imageTabHome, selectedImage: imageTabHome);
        let chatTabbarItem = UITabBarItem.init(title: "微聊", image: imageMake, selectedImage: imageMake);
        let aboutTabbarItem = UITabBarItem.init(title: "关于", image: imageMine, selectedImage: imageMine);
        homeVC.tabBarItem   = homeTabbarItem;
        chatVC.tabBarItem   = chatTabbarItem;
        aboutVC.tabBarItem  = aboutTabbarItem;
        
        let homeNaVC = IGNavigationController.init(rootViewController: homeVC);
        let chatNaVC = IGNavigationController.init(rootViewController: chatVC);
        let aboutNaVC = IGNavigationController.init(rootViewController: aboutVC);
        
        self.viewControllers = [homeNaVC,chatNaVC,aboutNaVC]
        self.delegate = self

    }
    
    
    internal func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController){
        let navc = viewController as! IGNavigationController
        let vc = navc.viewControllers[0]
        if(vc.isKindOfClass(ChatViewController.self)){
            let mkVC = MakeViewController.init(nibName: "MakeViewController", bundle: nil)
            self .presentViewController(mkVC, animated: true, completion: nil)
        }
        
        
    }

    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }


}
